/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.view.loan;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import src.domain.loan.Marketing;
import src.services.CRUEDService;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
@ManagedBean
@SessionScoped
public class SearchMarketingBean implements Serializable{
    private LazyDataModel<Marketing> lazyModel;  
    private Marketing selectedData;  
    private int pageSize = 10;
    private Integer marketingId;
    private String nama,cabang;

    public SearchMarketingBean() {
         selectedData = null;
        marketingId = null;
        nama = null;
        cabang = null;
        lazyModel = null;
    }

    public String getCabang() {
        return cabang;
    }

    public void setCabang(String cabang) {
        this.cabang = cabang;
    }

    public LazyDataModel<Marketing> getLazyModel() {
        return lazyModel;
    }

    public void setLazyModel(LazyDataModel<Marketing> lazyModel) {
        this.lazyModel = lazyModel;
    }

    public Integer getMarketingId() {
        return marketingId;
    }

    public void setMarketingId(Integer marketingId) {
        this.marketingId = marketingId;
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Marketing getSelectedData() {
        return selectedData;
    }

    public void setSelectedData(Marketing selectedData) {
        this.selectedData = selectedData;
    }
    
    
    public void handleClose() {
        selectedData = null;
        marketingId = null;
        nama = null;
        cabang = null;
        lazyModel = null;
    }
    
    public void loadData() {
        lazyModel = new LazyDataModel<Marketing>() {

            @Override
            public List<Marketing> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) { 
                                                
                int start = first;
                int end = first + pageSize;

            //    filters.put("marketingId", marketingId);
                filters.put("marketingName", nama);
             //   filters.put("approvalUid", "notnull");

                List<Marketing> list = (List) new CRUEDService().loadLazy("Marketing", start, end, sortField, sortOrder, filters);

                Integer count = new CRUEDService().countLazy("Marketing", filters);
                lazyModel.setRowCount(count);
                return list;
            }
        };
    }
    
    
}
